﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CluelessGame
{
    /// <summary>
    /// Interaction logic for AccusationScreen.xaml
    /// </summary>
    public partial class AccusationScreen : Window
    {
        
        private bool _ok = false;
        private ToggleButton _selectedCharacter;
        private ToggleButton _selectedWeapon;
        private ToggleButton _selectedRoom;

        public Character SelectedCharacter
        {
            get { return GetCharacterFromButton(_selectedCharacter); }
        }

        public Weapon SelectedWeapon
        {
            get { return GetWeaponFromButton(_selectedWeapon); }
        }

        public Room SelectedRoom
        {
            get { return GetRoomFromButton(_selectedRoom); }
        }


        public bool OK
        {
            get { return _ok; }
            private set { _ok = value; }
        }
        
        public AccusationScreen()
        {
            InitializeComponent();

            RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.Fant);
        }

        private void buttonAccuse_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedCharacter != null && _selectedWeapon != null && _selectedRoom != null)
            {
                OK = true;
                Close();
            }
            else
            {
                MessageBox.Show("You must select a character, weapon, and room.");
            }
        }

        private void buttonCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private Character GetCharacterFromButton(ToggleButton button)
        {
            if (button == toggleButtonPlum)
            {
                return GameManager.CurrentGameObjects.ProfessorPlum;
            }
            if (button == toggleButtonGreen)
            {
                return GameManager.CurrentGameObjects.MrGreen;
            }
            if (button == toggleButtonScarlet)
            {
                return GameManager.CurrentGameObjects.MissScarlet;
            }
            if (button == toggleButtonPeacock)
            {
                return GameManager.CurrentGameObjects.MsPeakcock;
            }
            if (button == toggleButtonWhite)
            {
                return GameManager.CurrentGameObjects.MsWhite;
            }
            if (button == toggleButtonMustard)
            {
                return GameManager.CurrentGameObjects.ColonelMustard;
            }
            return null;
        }

        private Weapon GetWeaponFromButton(ToggleButton button)
        {
            if (button == toggleButtonCandle)
            {
                return GameManager.CurrentGameObjects.Candlestick;
            }
            if (button == toggleButtonKnife)
            {
                return GameManager.CurrentGameObjects.Knife;
            }
            if (button == toggleButtonPipe)
            {
                return GameManager.CurrentGameObjects.Pipe;
            }
            if (button == toggleButtonRevolver)
            {
                return GameManager.CurrentGameObjects.Revolver;
            }
            if (button == toggleButtonRope)
            {
                return GameManager.CurrentGameObjects.Rope;
            }
            if (button == toggleButtonWrench)
            {
                return GameManager.CurrentGameObjects.Wrench;
            }
            return null;
        }

        private Room GetRoomFromButton(ToggleButton button)
        {
            if (button == toggleButtonBallroom)
            {
                return GameManager.CurrentGameObjects.Ballroom;
            }
            if (button == toggleButtonBilliardroom)
            {
                return GameManager.CurrentGameObjects.Billiardroom;
            }
            if (button == toggleButtonConservatory)
            {
                return GameManager.CurrentGameObjects.Conservatory;
            }
            if (button == toggleButtonDiningroom)
            {
                return GameManager.CurrentGameObjects.Diningroom;
            }
            if (button == toggleButtonHall)
            {
                return GameManager.CurrentGameObjects.Hall;
            }
            if (button == toggleButtonKitchen)
            {
                return GameManager.CurrentGameObjects.Kitchen;
            }
            if (button == toggleButtonLibrary)
            {
                return GameManager.CurrentGameObjects.Library;
            }
            if (button == toggleButtonLounge)
            {
                return GameManager.CurrentGameObjects.Lounge;
            }
            if (button == toggleButtonStudy)
            {
                return GameManager.CurrentGameObjects.Study;
            }
            return null;
        }

        private void toggleButtonPlum_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedCharacter != null && _selectedCharacter != toggleButtonPlum)
            {
                _selectedCharacter.IsChecked = false;
            }


            if (_selectedCharacter != toggleButtonPlum)
            {
                _selectedCharacter = toggleButtonPlum;
            }
            else
            {
                _selectedCharacter = null;
            }
        }

        private void toggleButtonMustard_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedCharacter != null && _selectedCharacter != toggleButtonMustard)
            {
                _selectedCharacter.IsChecked = false;
            }

            if (_selectedCharacter != toggleButtonMustard)
            {
                _selectedCharacter = toggleButtonMustard;
            }
            else
            {
                _selectedCharacter = null;
            }
        }

        private void toggleButtonScarlet_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedCharacter != null && _selectedCharacter != toggleButtonScarlet)
            {
                _selectedCharacter.IsChecked = false;
            }

            if (_selectedCharacter != toggleButtonScarlet)
            {
                _selectedCharacter = toggleButtonScarlet;
            }
            else
            {
                _selectedCharacter = null;
            }
        }

        private void toggleButtonGreen_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedCharacter != null && _selectedCharacter != toggleButtonGreen)
            {
                _selectedCharacter.IsChecked = false;
            }

            if (_selectedCharacter != toggleButtonGreen)
            {
                _selectedCharacter = toggleButtonGreen;
            }
            else
            {
                _selectedCharacter = null;
            }
        }

        private void toggleButtonPeacock_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedCharacter != null && _selectedCharacter != toggleButtonPeacock)
            {
                _selectedCharacter.IsChecked = false;
            }


            if (_selectedCharacter != toggleButtonPeacock)
            {
                _selectedCharacter = toggleButtonPeacock;
            }
            else
            {
                _selectedCharacter = null;
            }
        }

        private void toggleButtonWhite_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedCharacter != null && _selectedCharacter != toggleButtonWhite)
            {
                _selectedCharacter.IsChecked = false;
            }

            if (_selectedCharacter != toggleButtonWhite)
            {
                _selectedCharacter = toggleButtonWhite;
            }
            else
            {
                _selectedCharacter = null;
            }
        }

        private void toggleButtonCandle_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedWeapon != null && _selectedWeapon != toggleButtonCandle)
            {
                _selectedWeapon.IsChecked = false;
            }

            if (_selectedWeapon != toggleButtonCandle)
            {
                _selectedWeapon = toggleButtonCandle;
            }
            else
            {
                _selectedWeapon = null;
            }
        }

        private void toggleButtonKnife_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedWeapon != null && _selectedWeapon != toggleButtonKnife)
            {
                _selectedWeapon.IsChecked = false;
            }

            if (_selectedWeapon != toggleButtonKnife)
            {
                _selectedWeapon = toggleButtonKnife;
            }
            else
            {
                _selectedWeapon = null;
            }
        }

        private void toggleButtonRope_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedWeapon != null && _selectedWeapon != toggleButtonRope)
            {
                _selectedWeapon.IsChecked = false;
            }

            if (_selectedWeapon != toggleButtonRope)
            {
                _selectedWeapon = toggleButtonRope;
            }
            else
            {
                _selectedWeapon = null;
            }
        }

        private void toggleButtonRevolver_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedWeapon != null && _selectedWeapon != toggleButtonRevolver)
            {
                _selectedWeapon.IsChecked = false;
            }

            if (_selectedWeapon != toggleButtonRevolver)
            {
                _selectedWeapon = toggleButtonRevolver;
            }
            else
            {
                _selectedWeapon = null;
            }

        }

        private void toggleButtonWrench_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedWeapon != null && _selectedWeapon != toggleButtonWrench)
            {
                _selectedWeapon.IsChecked = false;
            }

            if (_selectedWeapon != toggleButtonWrench)
            {
                _selectedWeapon = toggleButtonWrench;
            }
            else
            {
                _selectedWeapon = null;
            }
        }

        private void toggleButtonPipe_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedWeapon != null && _selectedWeapon != toggleButtonPipe)
            {
                _selectedWeapon.IsChecked = false;
            }

            if (_selectedWeapon != toggleButtonPipe)
            {
                _selectedWeapon = toggleButtonPipe;
            }
            else
            {
                _selectedWeapon = null;
            }
        }

        private void toggleButtonBallroom_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedRoom != null && _selectedRoom != toggleButtonBallroom)
            {
                _selectedRoom.IsChecked = false;
            }

            if (_selectedRoom != toggleButtonBallroom)
            {
                _selectedRoom = toggleButtonBallroom;
            }
            else
            {
                _selectedRoom = null;
            }
        }

        private void toggleButtonBilliardroom_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedRoom != null && _selectedRoom != toggleButtonBilliardroom)
            {
                _selectedRoom.IsChecked = false;
            }


            if (_selectedRoom != toggleButtonBilliardroom)
            {
                _selectedRoom = toggleButtonBilliardroom;
            }
            else
            {
                _selectedRoom = null;
            }
        }

        private void toggleButtonConservatory_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedRoom != null && _selectedRoom != toggleButtonConservatory)
            {
                _selectedRoom.IsChecked = false;
            }

            if (_selectedRoom != toggleButtonConservatory)
            {
                _selectedRoom = toggleButtonConservatory;
            }
            else
            {
                _selectedRoom = null;
            }
        }

        private void toggleButtonDiningroom_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedRoom != null && _selectedRoom != toggleButtonDiningroom)
            {
                _selectedRoom.IsChecked = false;
            }

            if (_selectedRoom != toggleButtonDiningroom)
            {
                _selectedRoom = toggleButtonDiningroom;
            }
            else
            {
                _selectedRoom = null;
            }
        }

        private void toggleButtonHall_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedRoom != null && _selectedRoom != toggleButtonHall)
            {
                _selectedRoom.IsChecked = false;
            }

            if (_selectedRoom != toggleButtonHall)
            {
                _selectedRoom = toggleButtonHall;
            }
            else
            {
                _selectedRoom = null;
            }
        }

        private void toggleButtonKitchen_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedRoom != null && _selectedRoom != toggleButtonKitchen)
            {
                _selectedRoom.IsChecked = false;
            }

            if (_selectedRoom != toggleButtonKitchen)
            {
                _selectedRoom = toggleButtonKitchen;
            }
            else
            {
                _selectedRoom = null;
            }
        }

        private void toggleButtonLibrary_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedRoom != null && _selectedRoom != toggleButtonLibrary)
            {
                _selectedRoom.IsChecked = false;
            }

            if (_selectedRoom != toggleButtonLibrary)
            {
                _selectedRoom = toggleButtonLibrary;
            }
            else
            {
                _selectedRoom = null;
            }

        }

        private void toggleButtonLounge_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedRoom != null && _selectedRoom != toggleButtonLounge)
            {
                _selectedRoom.IsChecked = false;
            }

            if (_selectedRoom != toggleButtonLounge)
            {
                _selectedRoom = toggleButtonLounge;
            }
            else
            {
                _selectedRoom = null;
            }
        }

        private void toggleButtonStudy_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedRoom != null && _selectedRoom != toggleButtonStudy)
            {
                _selectedRoom.IsChecked = false;
            }

            if (_selectedRoom != toggleButtonStudy)
            {
                _selectedRoom = toggleButtonStudy;
            }
            else
            {
                _selectedRoom = null;
            }
        }
    }
}
